package org.yang.novel.wx.service.impl;

import static org.yang.common.Msg.*;

import org.yang.common.Msg;
import org.yang.novel.wx.dao.UserMapper;
import org.yang.novel.wx.entity.User;
import org.yang.novel.wx.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户服务实现
 * @author shichenyang
 * @email gyv12345@163.com
 * @date 2019/01/07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public Msg addUser(User user) {
        int i=  userMapper.insert(user);
        return i>0?ok(ADD_SUCCESS):err(ADD_ERR);
    }

    @Override
    public Msg updateUser(User user) {
        int i= userMapper.updateByParam(user);
        return i>0?ok(UPDATE_SUCCESS):err(UPDATE_ERR);
    }

    @Override
    public Msg delUser(User user) {
        int i=userMapper.del(user.getId());
        return i>0?ok(DEL_SUCCESS):err(DEL_ERR);
    }

    @Override
    public PageInfo getUsers(User user, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<User> users=userMapper.list(user);
        PageInfo pi=new PageInfo(users);
        return pi;
    }
}
